<?php


namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller {

    public function login(){
    	//后台登陆
    	if (IS_POST) {
    		
			$username = I('post.username');

			$sql = "SELECT * from `user` WHERE `username` = '$username'";
			$user = M('user');
			$query = $user -> query($sql);

			if(md5(I('post.password'))==$query[0]['password']){
				//用户名
				$_SESSION['username']=$query[0]['username'];
				//用户id
				$_SESSION['id']=$query[0]['id'];
								
				$this->success('登陆成功！',U('Admin/Index/index'));
			}else{

				$error = "alert('您的密码有错，请重新输入')";

				$this->assign('username', $username);
				$this->assign('error', $error);
				$this->display();
			}			
		}else{
		
			$this->display();
			// var_dump(dfiujfiuhfodsaifhjfioasfoi);
		}
		// layout(false);
		// $this->display();
	}


	public function loginout(){
		session_unset();
		session_destroy();
		$this->success('',U('/Admin/Login/login'),0);
	}

	private function check_verify($code, $id = ''){
    	//验证验证码
	    $verify = new \Think\Verify();
	    $check = $verify->check($code, $id);

	    if (!$check) {
	    	$this->error('注册信息或者验证码错误');
	    }
	}
}


?>